<%@ page import="com.app.ywms.rk.hyjh.Yhyjh" %>
<script>





    //    保存
    function onSave${pageId}(){

        $.messager.progress();	// display the progress bar

        var isValid = $('#form${pageId}').form('validate');
        if (!isValid){
            $.messager.progress('close');	// hide progress bar while the form is invalid
            return;
        }
        if($('#rowTable${pageId}').edatagrid('getRows')==null){
            $.messager.progress('close');
            return;
        }

        $('#rowTable${pageId}').edatagrid('saveRow');
        var head= $('#form${pageId}').serializeObject();

        var body = $('#rowTable${pageId}').edatagrid('getJSON');
        //检查行数据
        for(var i=0;i<body.length;i++){
            var vali= $('#rowTable${pageId}').edatagrid('validateRow',i);
            if(!vali) {
                $.messager.show({
                    title:'消息',
                    msg:'表体数据未填写完整！'
                });
                $.messager.progress('close');
                return;
            }

        }





        $.post( '${createLink(action: 'save')}',{'head':encodeURI(JSON.stringify(head)),'body':encodeURI(JSON.stringify(body))},function(json){

                    var row = $("#tb${pageId}").datagrid('getSelected');
                    $.messager.progress('close');	// hide progress bar while submit successfully

                    if($('#card${pageId}').showMessage(json)){//有错误数据


                        return;
                    }
                    onClose${pageId}();


                    $("#tb${pageId}").datagrid('reload')
                    $.messager.show({
                        title:'消息',
                        msg:'操作完成！'
                    });
                },
                'json'
        );

    }
    var curPanelId=null;
    //增加
    function onAdd${pageId}(data){

        var addurl
        if($.type(data)=='object'){
            addurl='${createLink(action: 'create')}?keys='+data.data+'&businessKey='+data.businessKey+'&sourceBillTypeCode='+data.sourceBillTypeCode;

        }else{
            addurl='${createLink(action: 'create')}?businessKey='+data;
        }
        $('#list${pageId}').panel('close');

        curPanelId='card${pageId}';

        var div=$('<div id="card${pageId}" />');
        div.appendTo($('#main${pageId}'));
        div.panel({fit:true,href:addurl,border:false,noheader:true});

    }

    //修改
    function  onEdit${pageId}(){
        var row=$('#tb${pageId}').datagrid('getSelected');
        if(row == null){//选择修改节点

            $.messager.show({title:'警告',msg:'请选择修改的数据'});
            return;
        }
        var editurl='${createLink(action:'edit')}/'+row.id
        $('#list${pageId}').panel('close');
        curPanelId='card${pageId}';

        var div=$('<div id="card${pageId}" />');
        div.appendTo($('#main${pageId}'));
        div.panel({fit:true,href:editurl,border:false,noheader:true});


    }

    //        删除
    function onDelete${pageId}(){

        var row=$('#tb${pageId}').datagrid('getSelected');
        var index = $('#tb${pageId}').datagrid('getRowIndex',row);
        if(row==null){
            $.messager.show({
                title:'消息',
                msg:'请选择需要删除的数据！'
            });
            return;
        };
        $.messager.confirm('${message(code:'default.delete.message',default: '删除数据')}',
                '${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}',
                function(r){
                    if(r){


                        $.post('${createLink(action: 'delete')}', { id: row.id },
                                function(data){


                                    $('#tb${pageId}').datagrid('deleteRow',index);
                                    $.messager.show({
                                        title:'消息',
                                        msg:'数据已经删除！'
                                    });
                                });
                    }
                }
        );
    }



    function onCheck${pageId}(){
        var row=$('#tb${pageId}').datagrid('getSelected');
       // var index = $('#tb${pageId}').datagrid('getRowIndex',row);
        if(row==null){
            $.messager.show({
                title:'消息',
                msg:'请选择需要审核的数据！'
            });
            return;
        };
        $.messager.confirm('${message(code:'default.check.message')}',
                '${message(code: 'default.button.check.confirm.message', default: 'Are you sure?')}',
                function(r){
                    if(r){


                        $.post('${createLink(action: 'check')}', { id: row.id },
                                function(data){

                                    if($(this).showMessage(data)){//有错误数据

                                        return;
                                    }

                                    $('#tb${pageId}').datagrid('reload');

                                });
                    }
                }
        );
    }




    function onUnCheck${pageId}(){
        var row=$('#tb${pageId}').datagrid('getSelected');
       // var index = $('#tb${pageId}').datagrid('getRowIndex',row);
        if(row==null){
            $.messager.show({
                title:'消息',
                msg:'请选择需要弃审的数据！'
            });
            return;
        };
        $.messager.confirm('${message(code:'default.uncheck.message')}',
                '${message(code: 'default.button.uncheck.confirm.message', default: 'Are you sure?')}',
                function(r){
                    if(r){


                        $.post('${createLink(action: 'uncheck')}', { id: row.id },
                                function(data){

                                    if($(document).showMessage(data)){//有错误数据

                                        return;
                                    }

                                    $('#tb${pageId}').datagrid('reload');

                                });
                    }
                }
        );
    }






    function onResize${pageId}(w,h){
        if(curPanelId==null)
            return;
        $('#'+curPanelId).panel('resize',{width:w,height:h});
    }

    function onClose${pageId}(){
        curPanelId==null;
        $('#card${pageId}').panel('destroy');
        $('#list${pageId}').panel('open');

    }


</script>
<div id="main${pageId}" style="padding: 3px" class="easyui-panel" data-options="fit:true,border:false,noheader:true,onResize:onResize${pageId}"  >
    <div id="list${pageId}" class="easyui-panel" title=""

         data-options="fit:true,border:false,noheader:true">

%{--按钮--}%
<div id="toolbar${pageId}">
    <g:addButton billTypeCode="YHYJH" handler="onAdd" pageId="${pageId}"></g:addButton>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="onEdit${pageId}()">${message(code: 'default.button.edit.label',default: '修改')}</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="onDelete${pageId}() ">
        ${message(code: 'default.button.delete.label',default: '删除')}
    </a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#tb${pageId}').datagrid('reload')">
        ${message(code: 'default.button.refresh.label',default: '刷新')}
    </a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="onOpenQuery${pageId}()">
        ${message(code: 'default.button.query.label',default: '查询')}
    </a>
    <a href="#" class="easyui-linkbutton"  plain="true" onclick="onCheck${pageId}()">
        ${message(code: 'default.button.check.label',default: '审核')}
    </a>

    <a href="#" class="easyui-linkbutton"  plain="true" onclick="onUnCheck${pageId}()">
        ${message(code: 'default.button.uncheck.label',default: '弃审')}
    </a>

</div>
<g:render template="list"></g:render>
</div>
</div>
